local skel = fk.CreateSkill {
  name = "rmt__jianzhong",
}

skel:addEffect(fk.HpRecover, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and not player:isKongcheng() and #player.room:getOtherPlayers(player) > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos, cards = room:askToChooseCardsAndPlayers(player, {
      min_num = 1,
      max_num = 1,
      min_card_num = 1,
      max_card_num = 1,
      targets = room:getOtherPlayers(player),
      pattern = ".|.|.|hand",
      skill_name = skel.name,
      prompt = "#rmt__jianzhong-target",
      cancelable = true,
    })
    if #tos > 0 and #cards > 0 then
      event:setCostData(self, {tos = tos, cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(event:getCostData(self).tos[1], event:getCostData(self).cards, false, fk.ReasonGive, player, skel.name)
  end,
})

skel:addEffect(fk.HpLost, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and table.find(player.room:getOtherPlayers(player), function(p) return not p:isNude() end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = table.filter(player.room:getOtherPlayers(player), function(p) return not p:isNude() end),
      skill_name = skel.name,
      prompt = "#rmt__jianzhong-choose",
      cancelable = true,
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = room:askToChooseCard(player, {
      target = event:getCostData(self).tos[1],
      flag = "he",
      skill_name = skel.name,
      prompt = "#rmt__jianzhong-discard::"..event:getCostData(self).tos[1].id,
    })
    room:throwCard(card, skel.name, event:getCostData(self).tos[1], player)
  end,
})

Fk:loadTranslationTable{
  ["rmt__jianzhong"] = "荐忠",
  [":rmt__jianzhong"] = "当你回复/失去体力后，你可以将一张手牌交给一名其他角色/弃置一名其他角色的一张牌。",

  ["#rmt__jianzhong-target"] = "荐忠：是否将一张手牌交给一名其他角色？",
  ["#rmt__jianzhong-choose"] = "荐忠：是否弃置一名其他角色的一张牌？",
  ["#rmt__jianzhong-discard"] = "荐忠：弃置 %dest 的一张牌",

  ["$rmt__jianzhong1"] = "天乃高且远，安可事事自下。",
  ["$rmt__jianzhong2"] = "若除贪官恶吏，天下自为之一清。",
}

return skel
